enum saveopendeletemode
{
	save,
	open,
	delete,
}

class SAVEorOPENorDELETE extends eui.Component implements  eui.UIComponent {
	okbutton:eui.Button
	canclebutton:eui.Button
	objectlist:eui.List
	scroller:eui.Scroller
	myCollection:eui.ArrayCollection

	mode:saveopendeletemode  
	public constructor() {
		super();
	}

	protected partAdded(partName:string,instance:any):void
	{
		super.partAdded(partName,instance);
	}


	protected childrenCreated():void
	{
		super.childrenCreated();
		this.okbutton.addEventListener(egret.TouchEvent.TOUCH_TAP,this.OK,this);
		this.canclebutton.addEventListener(egret.TouchEvent.TOUCH_TAP,this.cancle,this);
	
		this.scroller.viewport=this.objectlist
		var a=[]
		this.myCollection= new eui.ArrayCollection(a);
       
        this.objectlist.dataProvider= this.myCollection;
  
	
	}

	private OK()
	{
		
		
		if(this.mode==saveopendeletemode.save)
		{
			if(COBJJSONWRIT.getJSONWRIT.savedataobjdata(CMainEditor.editor.OBJECTNAME))
			     this.updata();
			else 
			{
				COBJJSONWRIT.getJSONWRIT.deletedataobjdata(CMainEditor.editor.OBJECTNAME)
				COBJJSONWRIT.getJSONWRIT.savedataobjdata(CMainEditor.editor.OBJECTNAME)
				this.updata();
			}
		}
		else if(this.mode==saveopendeletemode.open)
		{
		  if(!this.myCollection.length)return
		  //else if(!this.objectlist.selectedItem)return;
		  let objlist=this.objectlist.selectedItem;
          CBASE_MANAGE.getCBASE_MANAGE.clearALL();
		  CMainEditor.editor.clearALL();
		  ASSIST.getASSIST.clearALL();
          CBASE_MANAGE.getCBASE_MANAGE.getobjectByjson(objlist);
		  CMainEditor.editor.closesaveopendelete();
		  
		}
		else if(this.mode==saveopendeletemode.delete)
		{
		  if(!this.myCollection.length)return;
		  else if(!this.objectlist.selectedItem)return;
           COBJJSONWRIT.getJSONWRIT.deletedataobjdata(this.objectlist.selectedItem);
		  this.updata();
		}
	}
	private cancle()
	{
		 CMainEditor.editor.closesaveopendelete();
	}
	public pushdate()
	{

		 this.myCollection.removeAll();
         let a=COBJJSONWRIT.getJSONWRIT.showallnamespace()
		 console.log(a)
		 if(a==undefined)return;
		 for(let b=0;b<a.length;b++)
		 {
			 let c=a[b].Namespace;
			 this.myCollection.addItem(c)
		 }
	}
	public setmode(a:saveopendeletemode)
	{
       this.mode=a
	}
	public updata()
	{
		this.myCollection.removeAll()
		this.pushdate();
	}
	
}